/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config, { isServer }) => {
    config.module.rules.push({
      test: /\.LICENSE$/,
      use: 'null-loader'
    });
    
    config.module.rules.push({
      test: /\.node$/,
      use: 'null-loader'
    });
    
    config.resolve.alias = {
      ...config.resolve.alias,
      '@umijs/bundler-webpack/compiled/copy-webpack-plugin/LICENSE': false,
      '@umijs/bundler-webpack/compiled/copy-webpack-plugin': false,
      '@umijs/es-module-parser-win32-x64-msvc': false,
      '@umijs/max': false,
      '@umijs/openapi': false
    };
    
    return config;
  },
  transpilePackages: ['@ant-design/pro-components', '@ant-design/plots', 'antd-style'],
  experimental: {
    serverActions: true
  },
  async headers() {
    return [
      {
        source: '/api/:path*',
        headers: [
          { key: 'Access-Control-Allow-Credentials', value: 'true' },
          { key: 'Access-Control-Allow-Origin', value: '*' },
          { key: 'Access-Control-Allow-Methods', value: 'GET,DELETE,PATCH,POST,PUT' },
          { key: 'Access-Control-Allow-Headers', value: 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version' },
        ]
      }
    ]
  },
  async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: 'http://localhost:8012/api/:path*'
      }
    ]
  }
};

export default nextConfig;
